package com.proyecto.personas.modelo.servicio;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.proyecto.core.modelo.excepciones.GeneralException;
import com.proyecto.core.modelo.servicio.ServicioGenerico;

public class ServicioModoPagoSueldo extends ServicioGenerico {
	
	public void eliminar(Object pojo, boolean iniciaTransaccion) throws GeneralException {
		if (isValidacionActiva()){
			validacion.eliminar(pojo);
		}
		try {
			
			TransactionStatus status = transaccion.getTransaction(new DefaultTransactionDefinition());
			propiedadDAO.delete(pojo);
			transaccion.commit(status);
			
		} catch (org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException e) {
			if (e.getMostSpecificCause() instanceof org.hibernate.exception.ConstraintViolationException) {
				throw new GeneralException(
						"error." + claveProperties + ".eliminar.pkUsado");
			}
			if (e.getMostSpecificCause() instanceof org.hibernate.StaleStateException) {
				throw new GeneralException(
						"error." + claveProperties + ".eliminar.pkInvalida");
			}
			throw new GeneralException(
					"error." + claveProperties + ".eliminar");

		} catch (org.springframework.dao.DataAccessResourceFailureException e) {
			if (e.getMostSpecificCause() instanceof org.hibernate.exception.JDBCConnectionException) {
				throw new GeneralException(
						"error." + claveProperties + ".conexion");
			}
			throw new GeneralException(
					"error." + claveProperties + ".eliminar"); 	
		} catch (org.springframework.dao.DataAccessException e) {
			throw new GeneralException(
					"error." + claveProperties + ".eliminar");
		} catch (Exception e) {
			throw new GeneralException(
					"error." + claveProperties + ".desconocido");
		}
	}

}
